
# -*- coding: utf-8 -*-
# @Time    : 2022/6/10 10:38
# @File : connect_db.py
# @Author  : Yang

import pymysql


class Database():
    def __init__(self, host, database, username, pwd, port):
        self.db = pymysql.connect(host=host, database=database, user=username, password=pwd, port=port)
        self.cursor = self.db.cursor()

    def ex_sql(self, sql):
        self.cursor.execute(sql)

    def close_db(self):
        self.db.close()

    def commit_result(self):
        self.db.commit()

    def get_result(self):
        result = []
        data = self.cursor.fetchone()
        result.append(data[0])
        return result
